package com.ww.scm.service;



import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;

import com.ww.core.test.spring.SpringContextTestCase;
import com.ww.core.test.utils.DataUtils;
import com.ww.core.utils.DateUtils;
import com.ww.scm.constants.Constants;
import com.ww.scm.entity.mat.Bill;
import com.ww.scm.entity.mat.Storage;
import com.ww.scm.valueObject.mat.BillDetailVo;
import com.ww.scm.valueObject.mat.BillVo;

@ContextConfiguration(locations = { "/applicationContext-test.xml" })
public class MoveStorageTestCase extends SpringContextTestCase{

	private static final String TEST_BILL_TYPE_ID_1="C7403048BF6C430D8DE9F737E9690DDB";
	private static final String TEST_BILL_TYPE_ID_2="D1DE290DF5B1448CB57EAEC6DA5597B3";

	private static final String TEST_MAT_ID_1="C67ECD810D914231A531ACBB1E9C2F68";
	
	private static final String TEST_MAT_STATE_ID_1="29D1B4E71CDC461DAA81182CC40FAAF5";
	
	private static final String TEST_OPERATOR1="1001";
	
	@Autowired
	private StorageManager storageManager;

	public void setStorageManager(StorageManager storageManager) {
		this.storageManager = storageManager;
	}
	

	
	@BeforeClass
	//方法在整个类初始化之后调用，一般用来做测试准备工作。
	public static void setUpBeforeClass() throws Exception {

	}

	@AfterClass
	//方法在整个类结束之前调用，一般作测试的清理工作。
	public static void tearDownAfterClass() throws Exception {
	}

	@Before
	//方法在测试方法前调用，一般用来做测试准备工作。
	public void setUp() throws Exception {
		//运行测试方法前删除所有单据
		List<Bill> billList=storageManager.findBill();
		for (Bill bill : billList) {
			//storageManager.deleteBill(bill, TEST_OPERATOR1);
		}
	}

	@After
	//方法在测试方法后调用，一般作测试的清理工作。
	public void tearDown() throws Exception {
		
	}
	
	private static String billId;
	
	@Test
	//
	public void createStorage(){
		
		Date now=new Date();
		
		//单据1
		BillVo bill1=new BillVo();
		bill1.setBillCode("TestCreateStorage1");
		bill1.setBillDate(DateUtils.formatDate(now));
		bill1.setFillTime(DateUtils.formatDate(now));
		bill1.setBillTypeId(TEST_BILL_TYPE_ID_1);
		bill1.setTransactionTypeId(Constants.TRANSACTION_TYPE_ADD_ID);
		bill1.setOperator("1001");
		bill1.setOriginEntityId("FF85E8FB01704DA0AFF9825D9BA6A832");

		
		List<BillDetailVo> billDetailList=new ArrayList<BillDetailVo>();
		//单据明细1
		BillDetailVo billDetail1=new BillDetailVo();
		billDetail1.setTransactionDetailTypeId(Constants.TRANSACTION_DETAIL_TYPE_OUT_ID);
		billDetail1.setMaterielId(TEST_MAT_ID_1);
		billDetail1.setAmount(200.0);
		billDetail1.setStateId(TEST_MAT_STATE_ID_1);
		billDetail1.setOriginEntityId("FF85E8FB01704DA0AFF9825D9BA6A832");
		bill1.addBillDetail(billDetail1); 
		
		//保存单据
		Bill billPo1=storageManager.saveBill(bill1);
	}
	
	@Test	
	public void moveStorage(){
		
		Date now=new Date();
		
		//单据1
		BillVo bill1=new BillVo();
		bill1.setBillCode("TestMoveStorage22");
		bill1.setBillDate(DateUtils.formatDate(now));
		bill1.setFillTime(DateUtils.formatDate(now));
		bill1.setBillTypeId(TEST_BILL_TYPE_ID_2);
		bill1.setTransactionTypeId(Constants.TRANSACTION_TYPE_ADD_ID);
		bill1.setOperator("1001");
		bill1.setOriginEntityId("FF85E8FB01704DA0AFF9825D9BA6A832");
		bill1.setTargetEntityId("FF85E8FB01704DA0AFC9825D9BA6A832");
		bill1.setOtherDic1Id("5529CE5CE68C4AC38A582DD312C0721D");
		bill1.setOtherDic2Id("FF85E8FB01704DA0AFC9825D9BA6A832");

		//单据明细1
		BillDetailVo billDetail1=new BillDetailVo();
		billDetail1.setTransactionDetailTypeId(Constants.TRANSACTION_DETAIL_TYPE_IN_ID);
		billDetail1.setMaterielId(TEST_MAT_ID_1);
		billDetail1.setAmount(200.0);
		billDetail1.setPrice(20.0);
		billDetail1.setMoney(200.0*20);
		billDetail1.setOtherDic1Id("7BE4DB1DA2E04ED5B67139AB54592096");
		
		billDetail1.setStateId(TEST_MAT_STATE_ID_1);
		billDetail1.setOriginEntityId("FF85E8FB01704DA0AFF9825D9BA6A832");
		billDetail1.setTargetEntityId("FF85E8FB01704DA0AFC9825D9BA6A832");
		bill1.addBillDetail(billDetail1); 
		
		/*//单据明细2
		BillDetailVo billDetail2=new BillDetailVo();
		billDetail2.setTransactionDetailTypeId(Constants.TRANSACTION_DETAIL_TYPE_OUT_ID);
		billDetail2.setMaterielId(TEST_MAT_ID_1);
		billDetail2.setAmount(200.0);
		billDetail2.setStateId(TEST_MAT_STATE_ID_1);
		billDetail2.setOriginEntityId("FF85E8FB01704DA0AFC9825D9BA6A832");
		billDetail2.setTargetEntityId("FF85E8FB01704DA0AFF9825D9BA6A832");
		bill1.addBillDetail(billDetail2); */

		//保存单据
		Bill billPo1=storageManager.saveBill(bill1);
	}
	
	

}
